;
var helper = require("../../javascript/helper");
var db = require("../../javascript/mysql");
var mysql = new db.mysqlClient("accident");
function genProductInfo() {
    var projects = [];
    plan = {
        "planA": {
            "year": ["18-60"],
            "days": ["3d", "5d", "7d", "10d"],
            "people_count": ["1"],
            "accident_death": ["200000"],
            "accident_disable": ["90000"],
            "accident_medical": ["20000"],
            "airplane_death": ["300000"],
            "common_traffic": ["100000"],
            "train_death": ["300000"]
        },
        "planB": {
            "year": ["18-60"],
            "days": ["3d", "5d", "7d", "10d"],
            "people_count": ["1"],
            "accident_death": ["210000"],
            "accident_disable": ["100000"],
            "accident_medical": ["21000"],
            "airplane_death": ["310000"],
            "common_traffic": ["110000"],
            "train_death": ["310000"]
        }
    }
    for (k in plan) {
        data = helper.product([plan[k]["year"], plan[k]["days"], plan[k]["people_count"], plan[k]["accident_death"], plan[k]["accident_disable"], plan[k]["accident_medical"], plan[k]["airplane_death"], plan[k]["common_traffic"], plan[k]["train_death"]]);
        for (i = 0; i < data.length; i++) {
            dt = helper.formatProductInfo(data[i], plan[k]);
            projects.push(dt);

        }
    }; return projects;

}
function calcPremium(dt) {
    let day = dt["days"].replace("d", "");
    if (dt.accident_death == "200000") {
        idx = "0"
    } else (
        idx = "1"
    )
    let data = {
        "3": [6.99, "D000037261", 12.99, "D000037381"],
        "5": [11.99, "D000037291", 17.99, "D000037411"],
        "7": [17.99, "D000037321", 23.99, "D000037441"],
        "10": [22.99, "D000037351", 26.99, "D000037471"]
    };
    premium = data[day][idx * 2];
    rs = {
        "name": "任我游旅游保险计划",
        "company": "富德生命人寿",
        "price": premium
    }
    return rs;

};
var main = function ( ) {
    data = genProductInfo();
    for( i=0;i<data.length;i++){
        dt = data[i];
        rs = calcPremium( dt );
        console.log( rs );
        result = Object.assign( dt,rs);
        mysql.insertData( result );
    }
    mysql.close();
    
}